/* 2028. 找出缺失的观测数据 */
/**
 * @param {number[]} rolls
 * @param {number} mean
 * @param {number} n
 * @return {number[]}
 */
var missingRolls = function (rolls, mean, n) {
    const m = rolls.length
    const sum = mean * (m + n)
    const other = sum - (rolls.reduce((prev, next) => prev + next))
    const res = []
    if (other > n * 6 || other < n * 1) return res
    /* 取剩下值的平均值 */
    const averageValue = Math.floor(other / n)
    /* 向下取整多出来的的部分 */
    let temp = other - (averageValue * n)
    for (let i = 0; i < n; i++) {
        if (temp) {
            res.push(averageValue + 1)
            temp -= 1
        } else {
            res.push(averageValue)
        }
    }
    return res
};
const result = missingRolls(
    [4, 5, 6, 2, 3, 6, 5, 4, 6, 4, 5, 1, 6, 3, 1, 4, 5, 5, 3, 2, 3, 5, 3, 2, 1, 5, 4, 3, 5, 1, 5],
    4,
    40)
console.log('result :>>', result);